package com.app.tablet.receiver;

import com.app.tablet.R;
import com.app.tablet.view.MainPageActivity;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class AlarmReceiver extends BroadcastReceiver{
	
	private static final String TagProject = "Tablet-Project";
	private static final String TagPage = "AlarmReceiver-Page ::";

	@Override
	public void onReceive(Context context, Intent intent) {
		
		Log.i(TagProject, TagPage+"onReceive started.");
		
		String ns = Context.NOTIFICATION_SERVICE;
		NotificationManager mymanager = (NotificationManager)context.getSystemService(ns);
		
		int icon = R.drawable.pills0;
		String timerText = "Tablet alarm.";
		long when = java.lang.System.currentTimeMillis();
		Notification notification = new Notification(icon, timerText, when);
		
		Context context1 = context.getApplicationContext();
		CharSequence contentTitle = "My TabletApp";
		CharSequence contentText = "Time Up";
		Intent notificationIntent = new Intent(context, MainPageActivity.class);
		PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
		notification.setLatestEventInfo(context1, contentTitle, contentText, contentIntent);
		notification.defaults |= Notification.DEFAULT_SOUND;
		notification.defaults |= Notification.DEFAULT_LIGHTS;
		notification.defaults |= Notification.DEFAULT_VIBRATE;
		notification.flags |= Notification.FLAG_AUTO_CANCEL;
		notification.flags |= Notification.FLAG_INSISTENT;
		
		final int HELLO_ID = 1;
		mymanager.notify(HELLO_ID, notification);
		
		Log.i(TagProject, TagPage+"onReceive finished.");
	}

}
